package cn.Test01.controller;

import cn.Test01.entity.City;
import cn.Test01.entity.Province;
import cn.Test01.service.IliaoService;
import cn.Test01.service.impl.LiaoService;
import cn.entity.Status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/admin/Test")
public class TestController {
    @Autowired
    private LiaoService liaoService;

    @GetMapping("/test01")
    public String test(){
        return "admin/test01";
    }

    @ResponseBody
    @GetMapping("/getP")
    public Status getP(){
        System.out.println("PPPPP");
        Status status = new Status();
        List<Province> allProvinces = liaoService.findAllProvinces();
        if (allProvinces!=null){
            status.setFlag(true);
            status.setData(allProvinces);
            return status;
        }else {
            status.setFlag(false);
            status.setMessage("出现错误");
            return status;
        }
    }

    @ResponseBody
    @GetMapping("/getC")
    public Status getC(String Pid){
        Status status = new Status();
        List<City> cities = liaoService.finCityByPid(Pid);
        if (cities != null) {
            status.setFlag(true);
            status.setData(cities);
            return status;
        }else {
            status.setFlag(false);
            status.setMessage("查询城市出现错误");
            return status;
        }
    }

}
